﻿Option Explicit On
Option Strict On

Imports System.Windows.Forms

Public Class FormFader
    Private _i As Double = 0.0
    Private _MinOpacity As Integer = 0
    Private _MaxOpacity As Integer = 1

    Public Sub FadeIn(ByVal TargetForm As Form, ByVal FadeStep As Double)
        If TargetForm.Visible = False Then
            TargetForm.Opacity = 0
            TargetForm.Visible = True
        End If

        For _i = 0 To _MaxOpacity Step FadeStep
            TargetForm.Opacity = _i
            TargetForm.Refresh()
        Next
    End Sub

    Public Sub FadeOut(ByVal TargetForm As Form, ByVal FadeStep As Double)
        If TargetForm.Visible = False Then
            Return
        End If

        For _i = 1 To _MinOpacity Step -FadeStep
            TargetForm.Opacity = _i
            TargetForm.Refresh()
        Next
    End Sub
End Class